<?php
include '../config.php';
include '../scripts/utils.php';
include '../scripts/new_user.php';

$email = $_POST["email"];

$mysqli = new mysqli($MYSQL_HOST, $MYSQL_USERNAME, $MYSQL_PASSWORD, $MYSQL_DB_NAME);
if ($mysqli->connect_errno) {
	echo "ERR";
} else {
	$email = prepareString($mysqli, $email);
	$query = sprintf($VERIFY_EMAIL, $email);
	$verify = $mysqli->query($query);
	if (!$verify) {
		mysqli_free_result($verify);
		$mysqli->close();
		echo "ERR";
	} else {
		if ($verify->num_rows) {
			mysqli_free_result($verify);
			$mysqli->close();
			echo "KO";
		} else { 
			mysqli_free_result($verify);
			$mysqli->close();
			createNewUser();
			echo "OK";
		}
	}
}
?>